package com.tim.openoffice;

import java.io.File;
import java.io.IOException;

import com.tim.framework.util.FileUtil;

public class PdfProc {
	/**
	 * 将PDF文件转换为SWF文件.
	 * 
	 * @param pdfFile
	 *            PDF文件.
	 * @param outputFile
	 *            转换后的SWF文件.
	 * @return int 执行结果：0为执行成功，-1为要转换文件不存在, 其它为执行命令不成功.
	 */
	public static int convertPDF2SWF(File pdfFile, File outputFile) {
		if (!pdfFile.exists()) {
			return -1;
		}

		String command = "pdf2swf -z \"" + pdfFile.getAbsolutePath()
				+ "\" -o \"" + outputFile.getAbsolutePath() + "\"";

		try {
			return SysCmd.execCommand(command);
		} catch (IOException e) {
			e.printStackTrace();
			return -2;
		} catch (InterruptedException e) {
			e.printStackTrace();
			return -2;
		}
	}

	public static int convertPDF2SWF(File pdfFile){
		if (!pdfFile.exists()) {
			return 0;
		}
		return convertPDF2SWF(pdfFile, FileUtil.getFile(pdfFile, ".swf"));
	}

	public static int convertPDF2SWF(String pdfFile) {
		return convertPDF2SWF(new File(pdfFile));
	}
}
